<?php

namespace App\Http\Controllers\Coin;

use App\Http\Controllers\Controller;
use App\Library\Yunxin;
use App\Models\User;
use Illuminate\Http\Request;

class CenterController extends Controller
{
    /**
     * 修改头像
     * @author hxq
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function update_headimg(Request $request)
    {
        $uid     = $request->get('uid'); //用户id
        $headimg = $request->get('headimg');

        if (empty($uid) || empty($headimg)) {
            return respF(1003);
        }

        $user = User::find($uid);

        if (!$user) {
            return respF(2023);
        }
        $user->update([
            'headimg' => $headimg,
        ]);
        $model = new Yunxin\Yunxin();
        $model->change_yx($uid, '', config('alioss.host').'/'.$headimg, '');

        return response()->json(['status' => 1, 'msg' => '修改成功']);
    }

    /**
     * 修改昵称
     * @author hxq
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function update_nickname(Request $request)
    {
        $uid      = $request->get('uid'); //用户id
        $nickname = $request->get('nickname');

        if (empty($uid) || empty($nickname)) {
            return respF(1003);
        }

        $user = User::find($uid);

        if (!$user) {
            return respF(2023);
        }

        $user->update([
            'nickname' => $nickname,
        ]);
        $model = new Yunxin\Yunxin();
        $model->change_yx($uid, $nickname, '', '');
        return response()->json(['status' => 1, 'msg' => '修改成功']);
    }
}
